<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1 , user-scalable=no">
<title>题库题目查询</title>
<link href="__PUBLIC__/plugins/bootstrap.css" rel="stylesheet">
<link href="__PUBLIC__/plugins/bootstrap-dashen.css" rel="stylesheet">
<link href="__PUBLIC__/plugins/font-awesome.css" rel="stylesheet">
<link href="__PUBLIC__/plugins/animate.css" rel="stylesheet">
<link href="__PUBLIC__/plugins/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
</head>
<body style="margin-top:70px;">
<div class="container">
{include file="common/header" /}
	<div class="row"> 
		<div class="col-md-9 wow fadeInDown" data-wow-duration="0.5s">
			<div>
				<!-- Nav tabs -->
				<ul class="nav nav-tabs" role="tablist">
			    	<li><a href="__PUBLIC__/index.php">首页</a></li>
			    	<li role="presentation" class="active"><a href="#subjectListPanel" aria-controls="subjectListPanel" role="tab" data-toggle="tab">题库题目列表</a></li>
			    	<li role="presentation" ><a href="{:url('Subject/frontAdd')}" style="display:none;">添加题库题目</a></li>
				</ul>
			  	<!-- Tab panes -->
			  	<div class="tab-content">
				    <div role="tabpanel" class="tab-pane active" id="subjectListPanel">
				    		<div class="row">
				    			<div class="col-md-12 top5">
				    				<div class="table-responsive">
				    				<table class="table table-condensed table-hover">
				    					<tr class="success bold"><td>序号</td><td>题目id</td><td>题目标题</td><td>A</td><td>B</td><td>C</td><td>D</td><td>正确答案</td><td>得分</td><td>操作</td></tr>
				    					<?php
				    						/*计算起始序号*/
				    	            		$startIndex = ($currentPage-1) * $rows;
				    	            		$currentIndex = $startIndex+1;
				    	            		/*遍历记录*/
				    					?>
				    					{volist name="subjectRs" id="subject"}
 										<tr>
 											<td>{$currentIndex++}</td>
 											<td>{$subject.subjectId}</td>
 											<td>{$subject.title}</td>
 											<td>{$subject.a_option}</td>
 											<td>{$subject.b_option}</td>
 											<td>{$subject.c_option}</td>
 											<td>{$subject.d_option}</td>
 											<td>{$subject.rightOption}</td>
 											<td>{$subject.score}</td>
 											<td>
 												<a href="{:url('Subject/frontshow',array('subjectId'=>$subject['subjectId']))}"><i class="fa fa-info"></i>&nbsp;查看</a>&nbsp;
 												<a href="#" onclick="subjectEdit('{$subject.subjectId}');" style="display:none;"><i class="fa fa-pencil fa-fw"></i>编辑</a>&nbsp;
 												<a href="#" onclick="subjectDelete('{$subject.subjectId}');" style="display:none;"><i class="fa fa-trash-o fa-fw"></i>删除</a>
 											</td> 
 										</tr>
 										{/volist}
				    				</table>
				    				</div>
				    			</div>
				    		</div>

				    		<div class="row">
					            <div class="col-md-12">
						            <nav class="pull-left">
						                <ul class="pagination">
						                    <li><a href="#" onclick="GoToPage(<%=currentPage-1 %>,<%=totalPage %>);" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
						                     <?php
						                    	$startPage = $currentPage - 5;
						                    	$endPage = $currentPage + 5;
						                    	if($startPage < 1) $startPage=1;
						                    	if($endPage > $totalPage) $endPage = $totalPage;
						                    	for($i=$startPage;$i<=$endPage;$i++) {
						                    ?>
						                    <li class="<?php echo $currentPage==$i?"active":""; ?>"><a href="#"  onclick="GoToPage({$i},{$totalPage});">{$i}</a></li>
						                    <?php } ?>
						                    <li><a href="#" onclick="GoToPage({$currentPage + 1},{$totalPage});"><span aria-hidden="true">&raquo;</span></a></li>
						                </ul>
						            </nav>
						            <div class="pull-right" style="line-height:75px;" >共有{$recordNumber }条记录，当前第{$currentPage}/{$totalPage}页</div>
					            </div>
				            </div> 
				    </div>
				</div>
			</div>
		</div>
	<div class="col-md-3 wow fadeInRight">
		<div class="page-header">
    		<h1>题库题目查询</h1>
		</div>
		<form name="subjectQueryForm" id="subjectQueryForm" action="{:url('Subject/frontlist')}" class="mar_t15" method="post">
			<div class="form-group">
				<label for="title">题目标题:</label>
				<input type="text" id="title" name="title" value="{$title}" class="form-control" placeholder="请输入题目标题">
			</div>
            <input type=hidden name=currentPage id="currentPage" value="<%=currentPage %>" />
            <button type="submit" class="btn btn-primary" onclick="$('#currentPage').val(1);return true;">查询</button>
        </form>
	</div>

		</div>
	</div> 
<div id="subjectEditDialog" class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title"><i class="fa fa-edit"></i>&nbsp;题库题目信息编辑</h4>
      </div>
      <div class="modal-body" style="height:450px; overflow: scroll;">
      	<form class="form-horizontal" name="subjectEditForm" id="subjectEditForm" enctype="multipart/form-data" method="post"  class="mar_t15">
		  <div class="form-group">
			 <label for="subject_subjectId_edit" class="col-md-3 text-right">题目id:</label>
			 <div class="col-md-9"> 
			 	<input type="text" id="subject_subjectId_edit" name="subject.subjectId" class="form-control" placeholder="请输入题目id" readOnly>
			 </div>
		  </div> 
		  <div class="form-group">
		  	 <label for="subject_title_edit" class="col-md-3 text-right">题目标题:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="subject_title_edit" name="subject_title" class="form-control" placeholder="请输入题目标题">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="subject_a_option_edit" class="col-md-3 text-right">A:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="subject_a_option_edit" name="subject_a_option" class="form-control" placeholder="请输入A">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="subject_b_option_edit" class="col-md-3 text-right">B:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="subject_b_option_edit" name="subject_b_option" class="form-control" placeholder="请输入B">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="subject_c_option_edit" class="col-md-3 text-right">C:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="subject_c_option_edit" name="subject_c_option" class="form-control" placeholder="请输入C">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="subject_d_option_edit" class="col-md-3 text-right">D:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="subject_d_option_edit" name="subject_d_option" class="form-control" placeholder="请输入D">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="subject_rightOption_edit" class="col-md-3 text-right">正确答案:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="subject_rightOption_edit" name="subject_rightOption" class="form-control" placeholder="请输入正确答案">
			 </div>
		  </div>
		  <div class="form-group">
		  	 <label for="subject_score_edit" class="col-md-3 text-right">得分:</label>
		  	 <div class="col-md-9">
			    <input type="text" id="subject_score_edit" name="subject_score" class="form-control" placeholder="请输入得分">
			 </div>
		  </div>
		</form> 
	    <style>#subjectEditForm .form-group {margin-bottom:5px;}  </style>
      </div>
      <div class="modal-footer"> 
      	<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      	<button type="button" class="btn btn-primary" onclick="ajaxSubjectModify();">提交</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{include file="common/footer" /}
<script src="__PUBLIC__/plugins/jquery.min.js"></script>
<script src="__PUBLIC__/plugins/bootstrap.js"></script>
<script src="__PUBLIC__/plugins/wow.min.js"></script>
<script src="__PUBLIC__/plugins/bootstrap-datetimepicker.min.js"></script>
<script src="__PUBLIC__/plugins/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jsdate.js"></script>
<script>
/*跳转到查询结果的某页*/
function GoToPage(currentPage,totalPage) {
    if(currentPage==0) return;
    if(currentPage>totalPage) return;
    document.subjectQueryForm.currentPage.value = currentPage;
    document.subjectQueryForm.submit();
}

/*可以直接跳转到某页*/
function changepage(totalPage)
{
    var pageValue=document.subjectQueryForm.pageValue.value;
    if(pageValue>totalPage) {
        alert('你输入的页码超出了总页数!');
        return ;
    }
    document.subjectQueryForm.currentPage.value = pageValue;
    documentsubjectQueryForm.submit();
}

/*弹出修改题库题目界面并初始化数据*/
function subjectEdit(subjectId) {
	$.ajax({
		url :  "{:url('Subject/update')}?subjectId=" + subjectId ,
		type : "get",
		dataType: "json",
		success : function (subject, response, status) {
			if (subject) {
				$("#subject_subjectId_edit").val(subject.subjectId);
				$("#subject_title_edit").val(subject.title);
				$("#subject_a_option_edit").val(subject.a_option);
				$("#subject_b_option_edit").val(subject.b_option);
				$("#subject_c_option_edit").val(subject.c_option);
				$("#subject_d_option_edit").val(subject.d_option);
				$("#subject_rightOption_edit").val(subject.rightOption);
				$("#subject_score_edit").val(subject.score);
				$('#subjectEditDialog').modal('show');
			} else {
				alert("获取信息失败！");
			}
		}
	});
}

/*删除题库题目信息*/
function subjectDelete(subjectId) {
	if(confirm("确认删除这个记录")) {
		$.ajax({
			type : "POST",
			url: "{:url('Subject/deletes')}",
			data : {
				subjectIds : subjectId,
			},
			dataType: "json",
			success : function (obj) {
				if (obj.success) {
					alert("删除成功");
					$("#subjectQueryForm").submit();
					//location.href="{:url('Subject/frontlist')}";
				}
				else 
					alert(obj.message);
			},
		});
	}
}

/*ajax方式提交题库题目信息表单给服务器端修改*/
function ajaxSubjectModify() {
	$.ajax({
		url :  "{:url('Subject/update')}",
		type : "post",
		dataType: "json",
		data: new FormData($("#subjectEditForm")[0]),
		success : function (obj, response, status) {
            if(obj.success){
                alert("信息修改成功！");
                $("#subjectQueryForm").submit();
            }else{
                alert(obj.message);
            } 
		},
		processData: false,
		contentType: false,
	});
}

$(function(){
	/*小屏幕导航点击关闭菜单*/
    $('.navbar-collapse a').click(function(){
        $('.navbar-collapse').collapse('hide');
    });
    new WOW().init();

})
</script>
</body>
</html>

